home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / AIAT 1.0.1 / Headers / Analysis / IAAnalysis.h < prev    next >
Encoding:
Text File  |  1997-09-11  |  3.9 KB  |  124 lines  |  [TEXT/CWIE]

  1. // IAAnalysis.h
  2. //    Copyright:    © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4. #pragma once
  5. #ifndef IAAnalysis_h
  6. #define IAAnalysis_h
  7.  
  8. #pragma import on
  9.  
  10. #include "IACorpus.h"
  11.  
  12. #pragma IA_BEGIN_EXPORTS
  13.  
  14. class IATerm : public IAOrderedStorable {
  15. public:
  16.                     IATerm(const byte* d, uint32 l);
  17.     virtual            ~IATerm();                                // frees data
  18.  
  19.     IAStorable*        DeepCopy() const;
  20.     IABlockSize        StoreSize() const;
  21.     void            Store(IAOutputBlock* output) const;
  22.     IAStorable*        Restore(IAInputBlock* input) const;
  23.  
  24.     bool            LessThan(const IAOrderedStorable* neighbor) const;
  25.     bool            Equal(const IAOrderedStorable* neighbor) const;
  26.  
  27.     // non-virtual implementations for use by performance-critical code
  28.     // note: this means that LessThan & Equal mustn't be overridden by subclasses
  29.     bool            LessThanNonVirtual(const IAOrderedStorable* neighbor) const;
  30.     bool            EqualNonVirtual(const IAOrderedStorable* neighbor) const;
  31.     
  32.     byte*            GetData() const {return data;}
  33.     const uint32    GetDataLength() const {return dataLen;}
  34. private:
  35.                     IATerm(byte* d, uint32 l, bool makeCopy);    
  36.     byte*            AllocData(uint32 l) const;    
  37.                     IATerm(IATerm&);                        // don't define a copy constructor
  38.     byte*            data;                                    // alloated with IAMallocArraySized
  39.     const uint32    dataLen;
  40.  
  41. };
  42.  
  43. class IAToken : public IAObject {
  44. public:
  45.                             IAToken(IATerm* t, uint32 s, uint32 e)
  46.                                     : term(t), startPos(s), endPos(e) {}
  47.     IA_INLINE          ~IAToken() IA_INLINE_DEF_BODY(delete term)
  48.  
  49.     IATerm*                GetTerm() const {return term;}
  50.     const uint32        GetStartPosition() const {return startPos;}
  51.     const uint32        GetEndPosition() const {return endPos;}
  52.  
  53. private:
  54.                             IAToken(IAToken&);                // don't define a copy constructor
  55.     // the unique type
  56.     IATerm*                    term;
  57.     // the byte position of the first character in the text corresponding to this token
  58.     const uint32            startPos;
  59.     // one greater than the position of the last character corresponding to this token
  60.     const uint32            endPos;
  61.  
  62. };
  63.  
  64. class IATokenStream : public IAObject {
  65. public:
  66.     IATokenStream() {};
  67.     virtual      ~IATokenStream() {};// no-op dtor def
  68.     // Returns the next token in the stream, or NULL at end of stream.
  69.     virtual IAToken*        GetNextToken() = 0;
  70.     // Copies into dest a span of bytes from the source text .
  71.     // The span must start less than a buffer before the end of the last token read, and
  72.     // it may not extend past the end of the last token read.
  73.     // If it starts more than a buffer before, AnalysisSpanUnavailable is signalled.
  74.     virtual void            GetTextSpan(byte* dest, uint32 startPos, uint32 endPos) = 0;
  75. };
  76.  
  77. IAExceptionCode                    AnalysisSpanUnavailable = 'VASU';
  78.  
  79. class IATokenFilter : public IATokenStream {
  80. public:
  81.                             IATokenFilter(IATokenStream* s);    // source = s;    
  82.                             ~IATokenFilter();                    // delete source;
  83.     // GetText() on a filter delegates to its source by default.                
  84.     void                    GetTextSpan(byte* buffer, uint32 startPos, uint32 endPos) {
  85.                                 source->GetTextSpan(buffer, startPos, endPos);
  86.                             }
  87. protected:
  88.  
  89.         IATokenStream* GetTokenStream() const {return source;}
  90. private:
  91.                             IATokenFilter(IATokenFilter& o); // don't define a copy constructor
  92.     // The source of tokens to be filtered.
  93.         IATokenStream*            source;
  94.  
  95. };
  96.  
  97. class IAAnalysis : public IAObject {
  98. public:
  99.                             IAAnalysis(uint32 type);         // : analysisType(type) {}
  100.     IA_INLINE                ~IAAnalysis() IA_INLINE_DEF()// no-op dtor def
  101.  
  102.     
  103.  
  104.     // Initializes persistent state, writing analysis paramters to storage.
  105.     virtual void            Initialize(IAStorage* storage, IABlockID block); // {}
  106.     // Reads persistent state, checking that it’s consistent with current parameters.
  107.     virtual void            Open(IAStorage* storage, IABlockID block);         // {}
  108.  
  109.     // Builds and returns a tokenizer.
  110.     virtual IATokenStream*    MakeTokenStream(IADocText* docText) = 0;
  111.     // returns a prototype term, for bootstrapping sets of terms
  112.     virtual IATerm*            GetProtoTerm() = 0;
  113.     
  114.     const uint32 GetAnalysisType() const {return analysisType;}
  115.     
  116. private:
  117.     const uint32            analysisType;
  118. };
  119.  
  120. #pragma IA_END_EXPORTS
  121.  
  122. #pragma import reset
  123.  
  124. #endif